import { Dimension } from '../../engine/common/dimension';
import { Vector } from '../../engine/common/vector';
import { IWorld } from '../../engine/ecs/common/world.interface';
import { LocationComponent } from '../../engine/ecs/components/location.component';
import { SpriteAnimationRendererComponent } from '../../engine/ecs/components/sprite-animation-renderer.component';
import { Entity } from '../../engine/ecs/entities/entity';

export class ExplositionFactory {
  static create(world: IWorld, location: Vector, sprite: HTMLImageElement): Entity {
    const explosionEntity = new Entity('Explosion');
    world.addEntity(explosionEntity);
    world.attachComponentToEntity(LocationComponent, new LocationComponent(location), explosionEntity);
    world.attachComponentToEntity(
      SpriteAnimationRendererComponent,
      new SpriteAnimationRendererComponent(
        sprite,
        new Dimension(50, 50),
        [
          { sourceLocation: new Vector(0, 0), sourceDimension: new Dimension(25, 25) },
          { sourceLocation: new Vector(25, 0), sourceDimension: new Dimension(25, 25) },
          { sourceLocation: new Vector(50, 0), sourceDimension: new Dimension(25, 25) },
          { sourceLocation: new Vector(75, 0), sourceDimension: new Dimension(25, 25) },
        ],
        8,
        false
      ),
      explosionEntity
    );
    return explosionEntity;
  }
}
